package com.magold.logic.magold;

import java.util.LinkedList;
import java.util.List;

import com.magold.logic.item.ItemBeneficiary.ScoreSupports;
import com.magold.logic.item.ScoreListener;

public class ScoreCounter implements ScoreSupports {
	private List<ScoreListener> mScoreListeners;
	private int mScore;
	
	public ScoreCounter() {
		mScoreListeners = new LinkedList<ScoreListener>();
	}
	
	@Override
	public void addScore(int pPointsNum) {
		if (pPointsNum != 0) {
			mScore += pPointsNum;
			fire(pPointsNum);
		}
	}

	private void fire(int pPointsNum) {
		for (ScoreListener listener : mScoreListeners) {
			listener.onScoreChange(this, pPointsNum);
		}
	}

	@Override
	public int getScore() {
		return mScore;
	}

	@Override
	public void addScoreListener(ScoreListener pScoreListener) {
		if (pScoreListener != null) {
			mScoreListeners.add(pScoreListener);
		}
	}

	@Override
	public void removeScoreListener(ScoreListener pScoreListener) {
		mScoreListeners.remove(pScoreListener);
	}
}
